package com.shop.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import com.shop.dao.IRegistration;
import com.shop.db.DBUtil;
import com.shop.model.Registration;

public class RegistrationDao implements IRegistration{

	@Override
	public List<Registration> findAdmin() {
		// 
		return null;
	}

	@Override
	public Integer insert(Registration r) {
		Connection conn = DBUtil.getConn();
		PreparedStatement ptmt = null;
		String sql = "INSERT INTO register (username,password,email,name,sex,birthday) VALUES(?,?,?,?,?,?)";
		try {
			ptmt = conn.prepareStatement(sql);
			ptmt.setString(1, r.getUsername());
			ptmt.setString(2, r.getPassword());
			ptmt.setString(3, r.getEmail());
			ptmt.setString(4, r.getName());
			ptmt.setString(5, r.getSex());
			ptmt.setString(6, r.getBirthday());
			int i = ptmt.executeUpdate();
			return i;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (ptmt != null) {
				try {
					ptmt.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}

		}
		return null;
	}
	
}
